package com.example.finger.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.example.finger.R;
import com.example.finger.adpter.TaskInfoAdapter;
import com.example.finger.bean.Task;
import com.example.finger.bean.TaskSheet;
import com.google.gson.Gson;
import com.lyxmaster.lib.view.ListViewForScrollView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LU-MAC on 2018/11/25.
 */

public class TaskInfoDialog extends BaseDialog {
    private TextView textViewId;
    private TextView textViewStart;
    private TextView textViewEnd;
    private TextView xunjianStart;
    private TextView xunjianEnd;
    private TextView textViewOp;
    private TextView textViewRemark;
    private ListViewForScrollView listView;
    private ListViewForScrollView listViewA;
    private ListViewForScrollView listViewB;

    private Context context;
    private TaskSheet taskSheet;

    @Override
    public View createView(Context context, LayoutInflater inflater, ViewGroup container) {
        this.context = context;
        return inflater.inflate(R.layout.dialog_task_info, container, false);
    }

    public static TaskInfoDialog getInstance(String task) {
        TaskInfoDialog dialogFragment = new TaskInfoDialog();
        dialogFragment.setCanceledBack(false);
        dialogFragment.setCanceledOnTouchOutside(false);

        Bundle args = new Bundle();
        args.putString("title", task);
        dialogFragment.setArguments(args);

        return dialogFragment;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        textViewId = getView().findViewById(R.id.tv_id);
        textViewStart = getView().findViewById(R.id.tv_start);
        textViewEnd = getView().findViewById(R.id.tv_end);
        xunjianStart = getView().findViewById(R.id.tv_xunjianstart);
        xunjianEnd = getView().findViewById(R.id.tv_xunjianend);
        textViewOp = getView().findViewById(R.id.tv_op);
        textViewRemark = getView().findViewById(R.id.tv_ramrk);
        listView = getView().findViewById(R.id.listview);
        listViewA = getView().findViewById(R.id.listviewa);
        listViewB = getView().findViewById(R.id.listviewb);

        setCanceledBack(true);
        setCanceledOnTouchOutside(false);
        List<String> list = new ArrayList<>();
        taskSheet = new Gson().fromJson(getArguments().getString("title"), TaskSheet.class);

        for (int i =0; i<taskSheet.getPadLock().size(); i++){
            list.add(String.valueOf(taskSheet.getPadLock().get(i).getId()));
        }

        textViewId.setText(taskSheet.getTask().getBuweiname());
        textViewStart.setText("开始时间：" + taskSheet.getTask().getTimestart());
        textViewEnd.setText("结束时间：" + taskSheet.getTask().getTimeend());
        xunjianStart.setText("巡检开始：" + taskSheet.getTask().getXunjianstart());
        xunjianEnd.setText("巡检结束：" + taskSheet.getTask().getXunjianend());
        if(TextUtils.isEmpty(taskSheet.getTask().getRemark())){
            textViewRemark.setText("无");
        }else {
            textViewRemark.setText(taskSheet.getTask().getRemark());
        }
        listView.setAdapter(new TaskInfoAdapter(context,list));
        listViewA.setAdapter(new TaskInfoAdapter(context,taskSheet.getUsera()));
        listViewB.setAdapter(new TaskInfoAdapter(context,taskSheet.getUserb()));
    }
}
